import request from '@/utils/request'
const appCode = 'SAD-APP'
/**
 * JSON对象转formData
 * @param {Object} JSON对象
  */
export function json2FormData(params) {
  const formData = new FormData()
  Object.keys(params).forEach((key) => {
    formData.append(key, params[key])
  })
  return formData
}
export const getTabDefineDetail = (id) => {
  return request({
    url: `/app/v1/v2TabDefine/${id}`,
    method: 'get'
  })
}

// 根据目录id获取关联内容
export const getDirectoryContentIds = async(tabConfId) => {
  const filtersRaw = []
  if (tabConfId) {
    filtersRaw.push({ id: 'tabConfId', property: 'tabConfId', operator: '=', value: tabConfId })
  }
  const params = {
    pageFlag: false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw)
  }
  const data = json2FormData(params)
  const res = await request({
    method: 'post',
    url: `/app/v1/v2RefTabConfHelpCenterContent/page`,
    data
  })
  const list = (res && res.data && res.data.records) || []
  return list.map(v => v.helpContentId)
}
